﻿using System.Collections.Generic;
using KMF.Common;

namespace KMF.DAL
{
    public partial class GoldenTimeProductDb
    {
        public static int DelAllProductByGoldenTimeId(string GoldenTimeId)
        {
            var dao = SharedSqlDao;
            var command = dao.GetDbSprocCommand("WSPX_GoldenTimeProduct_DelByGoldID");
            try
            {
                command.Parameters.Add(dao.CreateParameter("@GoldenTimeId ", GoldenTimeId));
                return command.ExecuteNonQuery();
            }
            finally
            {
                command.Connection.Close();
            }
        }

        public static int DelGoldenTimeProductById(string productId, string GoldenTimeId)
        {
            var dao = SharedSqlDao;
            var command = dao.GetDbSprocCommand("WSPX_GoldenTimeProduct_DelId");
            try
            {
                command.Parameters.Add(dao.CreateParameter("@GoldenTimeId ", GoldenTimeId));
                command.Parameters.Add(dao.CreateParameter("@productId ", productId));
                return command.ExecuteNonQuery();
            }
            finally
            {
                command.Connection.Close();
            }
        }

        public static double UpdatePromotionUnit(string gId,int per,decimal priceOld)
        {
            var dao = SharedSqlDao;
            var command = dao.GetDbSprocCommand("WSPX_GoldenTimeProduct_UpdatePromotion");
            try
            {
                command.Parameters.Add(dao.CreateParameter("@GoldenTimeProductId ", gId));
                command.Parameters.Add(dao.CreateParameter("@promotionUnit ", per));
                command.Parameters.Add(dao.CreateParameter("@priceOld ", priceOld));
                return command.ExecuteNonQuery();
            }
            finally
            {
                command.Connection.Close();
            }
        }


        public static int GoldenTimeProduct_SelectByCampainAndProductId(string CampaintId, string productId)
        {
            var dao = SharedSqlDao;
            var command = dao.GetDbSprocCommand("WSPX_GoldenTimeProduct_SelectByCampainAndProductId");
            try
            {
                command.Parameters.Add(dao.CreateParameter("@CampaintId ", CampaintId));
                command.Parameters.Add(dao.CreateParameter("@ProductId ", productId));
                return command.ExecuteNonQuery();
            }
            finally
            {
                command.Connection.Close();
            }
        }

        public static int GoldenTimeProduct_AddToGrid(GoldenTimeProductDto dto)
        {
            var dao = SharedSqlDao;
            var command = dao.GetDbSprocCommand("WSPX_GoldenTimeProduct_AddToGrid");
            try
            {
                command.Parameters.Add(dao.CreateParameter("@Id ", dto.Id));
                command.Parameters.Add(dao.CreateParameter("@CampaintId ", dto.CampaintId));
                command.Parameters.Add(dao.CreateParameter("@ProductId ", dto.ProductId));
                command.Parameters.Add(dao.CreateParameter("@PromotionUnit ", dto.PromotionUnit));
                command.Parameters.Add(dao.CreateParameter("@PriceUnit ", dto.PriceUnit));
                command.Parameters.Add(dao.CreateParameter("@ViewTime ", dto.ViewTime));
                command.Parameters.Add(dao.CreateParameter("@IsHot ", dto.IsHot));
                command.Parameters.Add(dao.CreateParameter("@TimeShow ", dto.TimeShow));
                command.Parameters.Add(dao.CreateParameter("@Bought ", dto.Bought));
                command.Parameters.Add(dao.CreateParameter("@Active ", dto.Active));

                return command.ExecuteNonQuery();
            }
            finally
            {
                command.Connection.Close();
            }
        }
        public static List<GoldenTimeProductTopListDto> GetAllGoldenTimeProductByGoldenTimeId(string GoldenTimeId)
        {
            var dao = SharedSqlDao;
            var command = dao.GetDbSprocCommand("WSPX_GoldenTimeProduct_GetByGoldenTimeId");
            try
            {
                command.Parameters.Add(dao.CreateParameter("@GoldenTimeId", GoldenTimeId));
                var result = dao.GetDTOList<GoldenTimeProductTopListDto>(ref command);
                return result;
            }
            finally
            {
                command.Connection.Close();
            }
        }


    }
}
